 #This script reproduces Figure 1 in the main body of the paper. 
 
  setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
 
library(foreign)
library(rmeta)
library(plotrix)

districtdata<-read.dta("2010_district_data_for_R.dta")

attach(districtdata)

dempriority<-dpriimmig_pc10
reppriority<-rpriimmig_pc10

demposition<-dimmig_pc10
repposition<-rimmig_pc10
pdf("figure1_Rplot.pdf", width=7, height=7)
par(mfrow=c(1,2), oma=c(2,2,1,2), mar=c(4,4,1,1)+.01)
#Plot 1: All

plot(dempriority[deminc10==1] ~demposition[deminc10==1], col="grey50", ylim=c(1,4), xlim=c(1,4), main="A. Democratic Candidates", cex.main=.75, xlab="Position on Immigration" , ylab="Prioritization of Issue", pch=20, yaxt="n", xaxt="n", cex.lab=.65)
axis(1, at=(1:4), labels=c("Path-to-Citizenship", "2", "3", "4"), cex.axis=.55)
axis(2, at=(1:4), labels=c("Low", "Med.", "High", "Top"), las=2, cex.axis=.55)
reg1<-lm(dempriority[deminc10==1] ~demposition[deminc10==1])
abline(reg1)
   par(new=TRUE)
plot(dempriority[demchall10==1] ~demposition[demchall10==1], col="grey50",  ylab="", xlab="", yaxt="n", xaxt="n", ylim=c(1,4), xlim=c(1,4), pch=21)
reg2<-lm(dempriority[demchall10==1] ~demposition[demchall10==1])
abline(reg2, lty=3, col="grey50")
legend("bottomright", c("Democrat Incumbent", "Democrat Challenger"), pch=c(20, 21), bty="n", cex=.65, col=c("grey50", "grey50"))


plot(reppriority[repinc10==1] ~repposition[repinc10==1], col="black", ylim=c(1,4), xlim=c(4,7), pch=20, main="B. Republican Candidates", cex.main=.75, ylab="", xlab="Position on Immigration", yaxt="n", xaxt="n", cex.lab=.65)
axis(1, at=(4:7), labels=c( "4", "5", "6", "Forced to Return"), cex.axis=.55)
axis(2, at=(1:4), labels=c("Low", "Med.", "High", "Top"), las=2, cex.axis=.55)
reg3<-lm(reppriority[repinc10==1] ~repposition[repinc10==1])
abline(reg3)
   par(new=TRUE)
plot(reppriority[repchall10==1] ~repposition[repchall10==1], col="black", ylim=c(1,4), xlim=c(4,7), ylab="", xlab="", pch=21, yaxt="n", xaxt="n")
reg4<-lm(reppriority[repchall10==1] ~repposition[repchall10==1])
abline(reg4, lty=3, col="grey50")
legend("bottomright", c("Republican Incumbent", "Republican Challenger"), pch=c(20, 21), bty="n", cex=.65, col=c("black", "grey50"))
title("Position-Taking and Prioritization of the Illegal Immigration Issue", outer=TRUE, cex.main=.85)






rm(list=ls())


dev.off()
